#!/bin/bash
# nginx 日志切割
dat=`date +"%Y%m%d" `
mon=`date +"%Y%m"`
echo $dat

nginx_path="/data/log/nginx_log/"
mondir=$nginx_path$mon

/bin/echo $mondir
if [ ! -x "$mondir" ]; then
    echo "开始创建日期文件夹"
    mkdir "$mondir"
    echo "创建日期文件夹结束"
fi
/bin/echo `date +"%Y-%m-%d %H:%M:%S"`
/bin/echo ` ls -al $mondir`

# 声明需要分割的日志文件
logs=("default.access" "default.error")
for log_name in ${logs[@]}
do
    echo $log_name
    mv $nginx_path$log_name".log" $mondir/$log_name-$dat".log"
done

kill -USR1 `cat /opt/nginx1.10.3/logs/nginx.pid`
/bin/echo "success "
